﻿	<div class="site_map" align="left">Tài khoản <img src="/onlinemarket/img/navbit-arrow-right.png"/> Khách hàng</div>
    <div class="heading">
        <div class="heading_left"></div>
        <div class="heading_right"></div>
        <div class="heading_center">
            <img src="/onlinemarket/img/user.png" style="float: left; margin-top: 10px;"/>
        	<h3>Khách hàng</h3>
        </div>

        <div class="table">
            <div>&nbsp;</div>
            <form method="post" style="" id="Cusform" name="Cusform" action="/onlinemarket/customers/save">
                <table style="padding-left: 20px; padding-right: 80px;" class="noborder">
                <tr>
                    <td style="vertical-align: top;">
                        <img src="<?php
                            if ($iCustomer['Customer']['image'] == "") echo ('/onlinemarket/img/unknown_person.jpg');
                            else echo('/onlinemarket/img/Customer/'.$iCustomer['Customer']['image'].''); ?>" width="150" onclick="uploadImage()"/>
                        
                    </td>
                    <td>
                        <table>
                            <input type="hidden" id="id" name="id" value="<?php echo($iCustomer['Customer']['id']); ?>"/>
                            <tr>
                                <td><font color="red">*</font>Họ đệm</td>
                                <td><input style="width: 220px;" type="text" name="lastname" id="lastname" value="<?php echo($iCustomer['Customer']['lastname']); ?>"/></td>
                                <td style="width: 50px;">&nbsp;</td>
                                <td><font color="red">*</font>Tên</td>
                                <td><input style="width: 220px;" type="text" name="firstname" id="firstname" value="<?php echo($iCustomer['Customer']['firstname']); ?>"/></td>
                            </tr>
                            <tr>
                                <td><font color="red">*</font>Tên đăng nhập</td>
                                <td><input style="width: 220px;" type="text" name="username" id="username" value="<?php echo($iCustomer['Customer']['username']);?>"/> </td>
                                <td style="width: 30px;">&nbsp;</td>
                                <td><font color="red">*</font>Mật khẩu</td>
                                <td><input style="width: 220px;" type="password" name="password" id="password" value="<?php echo($iCustomer['Customer']['password']); ?>"/></td>
                            </tr>
                            <tr>
                                <td>Ngày sinh</td>
                                <td><input style="width: 220px; text-align: center;" type="text" name="birthday" id="birthday" readonly="true" value="<?php if ($iCustomer['Customer']['birthday'] != "") echo(date("d-m-Y", strtotime($iCustomer['Customer']['birthday']))); ?>"/></td>
                                <td style="width: 30px;">&nbsp;</td>
                                <td>Ðịa chỉ</td>
                                <td><input style="width: 220px;" type="text" name="address" id="address" value="<?php echo($iCustomer['Customer']['address']); ?>"/></td>
                            </tr>
                            <tr>
                                <td>Email</td>
                                <td><input style="width: 220px;" type="text" name="email" id="email" value="<?php echo($iCustomer['Customer']['email']); ?>"/></td>
                                <td style="width: 30px;">&nbsp;</td>
                                <td>Ðiện thoại</td>
                                <td><input style="width: 220px;" type="text" name="phone" id="phone" style="text-align: center;" value="<?php echo($iCustomer['Customer']['phone']); ?>"/></td>
                            </tr>
                            <tr>
                                <td>Ảnh đại diện</td>
                                <td>
                                    <form action="/onlinemarket/customers/upload_image" method="post" enctype="multipart/form-data">
                                        <input type="file" name="file" id="file" onchange="uploadImage()"/>
                                    </form>
                                </td>
                                <td style="width: 30px;">&nbsp;</td>
                                <td>Trạng thái</td>
                                <td>
                                    <select id="status" name="status">
                                        <option value="1" <?php if($iCustomer['Customer']['currentStatus'] == 1) echo('selected="selected"'); ?>>Active</option>
                                        <option value="0" <?php if($iCustomer['Customer']['currentStatus'] == 2) echo('selected="selected"'); ?>>Inactive</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="5" align="right">
                                    <input type="submit" value="Lưu"/>
                                    <input type="button" value="Hủy" onclick="onCancel();"/>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="padding-bottom: 0;"><hr /></td>
                </tr>
                <tr>
                    <td colspan="2" style="padding-top: 0;">Trường <font color="red">*</font> yêu cầu phải nhập</td>
                </tr>
                </table>
            </form>
        </div>
<table class="border" style="width: 100%;">
    <tr>
        <td colspan="7" align="right"><a href="/onlinemarket/customers">Thêm khách hàng mới</a></td>
    </tr>
    <tr>
        <th>Họ và tên</th>
        <th>Tên đăng nhập</th>
        <th>Ngày sinh</th>
        <th>Địa chỉ</th>
        <th>Email</th>
        <th>Điện thoại</th>
        <th>Chức năng</th>
    </tr>


<?php foreach ($customers as $cust) : ?>
<tr>
    <td><?php echo($cust['Customer']['lastname']." ".$cust['Customer']['firstname']); ?></td>
    <td><?php echo($cust['Customer']['username']); ?></td>
    <td style="text-align: center;"><?php if ($cust['Customer']['birthday'] != "") echo(date("d-m-Y", strtotime($cust['Customer']['birthday']))); ?></td>
    <td><?php echo($cust['Customer']['address']); ?></td>
    <td><?php echo($cust['Customer']['email']); ?></td>
    <td><?php echo($cust['Customer']['phone']); ?></td>
    <td>
        <img style="cursor: pointer;" src="/onlinemarket/img/system/bt_edit.png" 
        onclick="onEdit('/onlinemarket/customers/index/<?php echo($cust['Customer']['id']);?>')" alt="Sửa" title="Sửa"/>
        <img style="cursor: pointer;" src="/onlinemarket/img/system/bt_delete.png" onclick="onEdit('/onlinemarket/customers/delete/<?php echo($cust['Customer']['id']);?>')" alt="Xóa" title="Xóa"/>
    </td>
</tr>
<?php endforeach; ?>

</table>
<div style="text-align: right;">
    <?php echo $this->Paginator->numbers();?>
    <?php echo $this->Paginator->prev('« Previous', null, null, array('class' => 'disabled')); ?>
    <?php echo $this->Paginator->next('Next »', null, null, array('class' => 'disabled')); ?>
</div>
</div>
<script>

    function onEdit(link) {
        window.location = link;
    }
    function onCancel() {
        $('form:first').slideUp('slow');
        $('#topTable').hide();
    }
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split('&');
        for (var i=0; i<vars.length; i++) {
            var pair = vars[i].split('=');
            if (pair[0] == variable) {
                return pair[1];
            }
        }
    };

    $(document).ready(function() {
        Calendar.setup({
           inputField: "birthday",
           ifFormat: "%d-%m-%Y",
           daFormat: "%d-%m-%Y",
           timeFormat: "12"
        });
    });
</script>